const app = getApp()

Page({
  data: {
    flag: 0,
    noteMaxLen: 300, // 最多放多少字
    info: "",
    noteNowLen: 0,//备注当前字数
    userStars: [
      "../../images/star.png",
      "../../images/star.png",
      "../../images/star.png",
      "../../images/star.png",
      "../../images/star.png",
    ],
    wjxScore: 5,
  },
  onLoad:function(options){
    console.log(options)
    var that=this;
    that.setData({
      pingjia_id: options.pingjia_id,
    })
  },
  // 星星点击事件
  starTap: function (e) {
    var that = this;
    var index = e.currentTarget.dataset.index; // 获取当前点击的是第几颗星星
    var tempUserStars = this.data.userStars; // 暂存星星数组
    var len = tempUserStars.length; // 获取星星数组的长度
    for (var i = 0; i < len; i++) {
      if (i <= index) { // 小于等于index的是满心
        tempUserStars[i] = "../../images/star.png";
        that.setData({
          wjxScore: i + 1,
        })
      } else { // 其他是空心
        tempUserStars[i] = "../../images/star-kong.png"
      }
    }
    // 重新赋值就可以显示了
    that.setData({
      userStars: tempUserStars
    })
  },
  // 监听字数
  bindTextAreaChange: function (e) {
    var that = this
    var value = e.detail.value,
      len = parseInt(value.length);
    if (len > that.data.noteMaxLen)
      return;
    that.setData({ info: value, noteNowLen: len })

  },
  // 提交清空当前值
  bindSubmit: function (e) {
    console.log(e)
    var that = this;
    if (e.detail.value.Description==""){
      wx.showToast({
        title: '必填',
        icon: 'sucnonecess',
      })
      return ;
    }
    var formData = e.detail.value;
    wx.request({
      url: app.globalData.apiUrl + 'Order/pingjia',
      data: formData,
      header: {
        'Content-Type': 'application/json'
      },
      method: 'POST',
      success: function (res) {
        if (res.data.status == 1) {
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          })
          setTimeout(function () {
            wx.redirectTo({
              url: '/pages/personal/dingdan/dingdan',
            })
          }, 2000);
          
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          })
        }
        
      }
    })

  },
  changeColor1: function () {
    var that = this;
    that.setData({
      flag: 1
    });
  },
  changeColor2: function () {
    var that = this;
    that.setData({
      flag: 2
    });
  },
  changeColor3: function () {
    var that = this;
    that.setData({
      flag: 3
    });
  },
  changeColor4: function () {
    var that = this;
    that.setData({
      flag: 4
    });
  },
  changeColor5: function () {
    var that = this;
    that.setData({
      flag: 5
    });
  },


})
